﻿using ET;
using Marx;

namespace Demo
{
    public class Startup : IMarxStartup
    {
        public void UseDLL(IConfiguration app)
        {
            app.UseNetworkDLL();
            app.UseDLCDLL();
            app.UseDLL(typeof(Global).Assembly);
        }

        public void Configure(IConfiguration app, IMarxEnvironment env)
        {
            var configs = Global.Instance.Configs;
            if(Global.Instance.DevelopMode)
            {
                app.SetDevelop(1);
            }
            else
            {
                app.SetDevelop(0);
            }

            app.UseLitJson();

            //network
            app.UseTcp();
            app.UseClientNetwork();

            //dlc
            app.SetBundleRoot(configs.DLCWorkingDirectory);
            app.SetDLCMainBundle(configs.DLCMainBundleFileName);
            app.SetDLCFile(configs.DLCVersionFileName, configs.DLCVersionDetailFileName, configs.DLCBundleInfoFileName);

            app.UseDLC();
            app.UseLocalDLC(Global.Instance.LocalDLC);
            if (Global.Instance.EnableRemoteDLC)
            {
                app.UseRemoteDLC(configs.DLCVersionUrl, configs.DLCVersionDetailUrl, 
                    configs.DLCBundleInfoUrl, configs.DLCBundleRootUrl);
            }
#if UNITY_EDITOR
            if (!Global.Instance.EnableEditorDLC)
            {
                ResHelper.RegisterLoader(ResType.DLC, new EditorAssetLoader());
            }
#endif

            //ui
            app.UseMarxUI(configs.UIPopupRootPath);
            if(Global.Instance.ShowAppInfo)
            {
                app.UseAppInfo(ResType.Resources);
                app.UseAppInfoIcon(configs.UIAppInfoIconPath);
                app.UseAppInfoPanel<AppInfoPanelController>(configs.UIAppInfoPanelPath);
            }


            //templates
            ConfigLoader.Instance.Initialize(configs.XlsTemplatePath, configs.XlsDetailFilePath);

            //hearbeat
            app.UseHeartbeat(2000);
            app.UseHeartbeatCheck(2000, 10000);
        }
    }
}
